﻿<form id="mainform" name='frm' method=post action="">
	
		<!-- class="item" onclick="add()" id="itemButton1" title="Thêm mới">
				<div id="addnew-global-button"></div>
			</div>
			<div class="item" onclick="del()" id="itemButton0" title="Xóa">
				<div id="delete-global-button"></div>
			</div>			
		</div>-->
   	 <table width = 100% id="id-form">
		<tr>
			<td>			
			<input type='button' value="Add New" onclick="add()"/>
			<input type='button' value="Publish" onclick="active()"/>
			<input type='button' value="Unpublish" onclick="inactive()" />				
			<input type='button' value="Delete" onclick="delete()" />			
			</td>
		</tr>
		<tr>
			<td>
				<a href='timkiemAction()' > A </a>
				|
				<a href='timkiemAction()' > B </a>
				|
				<a href='timkiemAction()' > C </a>
				|
				<a href='timkiemAction()' > D </a>
				|
			</td>
		</tr>		 
        <tr>
            <td width="10%" nowrap="nowrap">Tên cửa hàng &nbsp;&nbsp;			
                <input type=text class="inp-form" name="storename" value="<?=$this->name?>">
            </td>
            <td >
			&nbsp;&nbsp;
            </td>	
			<td width="10%" nowrap="nowrap">Email &nbsp;&nbsp;
			<input type=text class="inp-form" name="email" value="<?=$this->email?>" >
            </td>
            <td>
                &nbsp;&nbsp;
            </td>			
			<td width="10%" nowrap="nowrap">Loại &nbsp;&nbsp;
				<select type=text name="storecategory" value="<?=$this->storecategory?>">
				<option value="">-- Chọn loại cửa hàng --</option>
				<?php 
						foreach($this->listStoreCategory as $item){
							if($item['PARENTID']==0){
								$level = 0;
								$spaceLevel = "__";
								echo '<option  value="'.$item['STORECATEGORYID'].'" ';
								if($item['STORECATEGORYID'] == $this->storecategory)
									echo 'selected';
								else 
									echo '';
								echo '><b>'.$item['NAME'].'</b></option>';
							}
							else {
								echo '<option value="'.$item['STORECATEGORYID'].'" ';
								if($item['STORECATEGORYID'] == $this->storecategory)
									echo 'selected';
								else 
									echo '';
								echo '><b>|____'.$item['NAME'].'</b></option>';
							}
						}
					?>
				</select>
            </td>
            <td > 
			&nbsp;&nbsp;           
            </td>
			<td width="10%" nowrap="nowrap">Trạng thái &nbsp;&nbsp;
				<select type=text name="status" value="<?=$this->status?>">
				<option value="">-- Chọn trạng thái --</option>
				<option value=""> published </option>
				<option value=""> unpublished </option>
				<?php 
						// foreach($this->listTrangThai as $item){
								// echo '<option  value="'.$item['STATUS'].'" ';
								// if($item['STOREID'] == $this->data['STOREID'])
									// echo 'selected';
								// else 
									// echo '';
								// echo '><b>'.$item['NAME'].'</b></option>';
						// }
					 ?>
				</select>
            </td>
            <td >
                
            </td>
			
			<td nowrap="nowrap">
			&nbsp;&nbsp;           
            </td>
            <td>
				<input type='button' onclick="timkiemAction()" value="Tìm kiếm">
            </td>
        </tr>
    </table >
    <table style="margin-top: 10px" border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
        <thead>
            <tr class="alternate-row">
                <!--<th width="2%" style="text-align: center" nowrap="nowrap">STT</th>-->
                <th width="5%" style="text-align: center; vertical-align: middle" nowrap valign="center">
                    <input type=checkbox name=DELALL onclick="SelectAllU(this,'DEL')">
                </th>
                <th width="10%" style="text-align: left">Tên cửa hàng</th>
        		<th width="15%" style="text-align: left">Địa chỉ</th>
                <th width="10%" style="text-align: center" style="text-align: left">Người dùng</th>
				<th width="10%" style="text-align: center" style="text-align: left">Email</th>
				<th width="10%" style="text-align: center" style="text-align: left">Ngày tạo</th>
				<th width="15%" style="text-align: center" style="text-align: left">Ngày chỉnh sửa gần nhất</th>
				<th width="10%" style="text-align: center" style="text-align: left">Trạng thái</th>
				<th width="20%" style="text-align: center" style="text-align: left">Thao tác</th>
            </tr>
        </thead>
        <tfoot>
        </tfoot>
        <tbody>
            <?php
if (count($this->data) == 0) {
	echo "<tr><td colspan=9>Không có dữ liệu được tìm thấy</td></tr>";
} else {
	$stt = 1;
}
foreach ($this->data as $item) {
			   ?>
            <tr>
                <!--<td name="stt" style="text-align: center" ><?=$stt ?></td>-->
                <td style="text-align: center; vertical-align: middle">
                    <input id="<?=$item['STOREID'] ?>" type="checkbox" name="DEL[]" value="<?=$item['STOREID'] ?>" />
                </td>
                <td> 
                <a href="#" onClick="ItemClickU(<?php echo $item['STOREID'] ?>)">
                        <?=$item['NAME']; ?></a>
                </td>
				<td> 
                <a href="#" onClick="ItemClickU(<?php echo $item['STOREID'] ?>)">
                        <?=$item['ADDRESS']; ?></a>
                </td>
				 <td> 
				 <a href="#" onClick="ItemClickU(<?php echo $item['STOREID'] ?>)">
                        <?=$item['USERID']; ?></a>
                </td>
				 <td> 
				 <a href="#" onClick="ItemClickU(<?php echo $item['STOREID'] ?>)">
                        <?=$item['EMAIL']; ?></a>
                </td>
				 <td> 
				 <a href="#" onClick="ItemClickU(<?php echo $item['STOREID'] ?>)">
                        <?=$item['CREATEDDATE']; ?></a>
                </td>
				 <td> 
				 <a href="#" onClick="ItemClickU(<?php echo $item['STOREID'] ?>)">
                        <?=$item['LASTUPDATE']; ?></a>
                </td>
				 <td> 
				 <a href="#" onClick="ItemClickU(<?php echo $item['STOREID'] ?>)">
                        <?=$item['STATUS']; ?></a>
                </td>
                <td style="text-align: center" onClick="ItemClickU(<?php echo $item['STOREID'] ?>)"><span id="status<?=$item['STOREID'] ?>">
                        
                        <?php if ($item['STATUS'] != 1) {
		echo '<font color="#004FA0"> Chưa kích hoạt</font>';
	} else {
		echo 'Đã kích hoạt';
	} 	?></a>
                    </span>
                </td>
            </tr>
			
            <?php $stt++;
					}
				 ?>
        </tbody>
    </table>

</form>
<script>
    function ItemClickU(id)
    {
        document.frm.action = "/storemanagement/store/input/id/"+id;
        document.frm.submit();
    }
	
    function add(){
        document.location.href='/storemanagement/store/input';
    }
	
	function timkiemAction(){
        common.submitForm(document.frm,'');
    }
	
    function SelectAllU(selobj,childobj){
         var arr = document.getElementsByName(childobj+"[]");
         for(var i=0;i<arr.length;i++){
            arr[i].checked = selobj.checked;
         }
    }
	
    function del()
    { 
		  var ln = 0;
		  var arr = document.getElementsByName('DEL[]');
		  alert(arr.length);
		  for(var i = 0 ; i < arr.length ;i++ )
		  {
				if(arr[i].checked == true )
				{
					ln = 1;
					break;
				}	
		  }
          
          if(ln == 1)
          {
                  if(confirm("<?php echo "Bạn có muốn xóa không?"; ?>")){	
                        document.frm.action="/storemanagement/store/delete";
                        document.frm.method="post";
                        document.frm.submit();
                  }
          }
          else
          {
				if(arr.length == 0)
					{
						alert("Bạn phải chọn một dòng để xóa");
					}
					else
					{
						// if( confirm(<?php echo "Lưu ý: Chỉ có thể xóa các item không có item con. Chọn lại?" ?>))
						// {
							// for(var i = 0 ; i < arr.length ;i++ )
							// {
								// var anItem = $this->data[i];
				
								// if(arr[i].checked == true && && anItem['SUBCOUNT'] > 0)
								// {
									// arr[i].checked = false;
								// }
							// }
						// }
					}
          }
    }

</script>
